<?php
namespace app\index\controller;

use app\admin\model\Authorizer;
use app\admin\model\Replyfansaccount;
use EasyWeChat\Factory;
use think\facade\Url;
use think\swoole\facade\Task;

class Index
{
    public function index()
    {
        Url::build('@admin/adminindex/adminindex');
        return redirect( url('@admin/adminindex/adminindex'));
    }

    public function entrylink($pool='',$domain='')
    {
        if($pool != '' && $domain != ''){
            $list = Replyfansaccount::where(['accountpool'=>$pool,'delstatus'=>1])->select();
            $count = Replyfansaccount::where(['accountpool'=>$pool,'delstatus'=>1])->count();
            if($count == 1){
                $num = 0;
            }else{
                $num = mt_rand(0,$count-1);
            }
            $ghid = $list[$num]['gh_id'];
            return $ghid;
        }else{
            return redirect('https://www.qq.com');
        }
    }

    public function test()
    {
        $platform = Factory::openPlatform(config('wechat.open_platform.default'));
        $url = $platform->getPreAuthorizationUrl('http://wechat.nanxuncn.cn/wechat/index/callback');
        // 异步任务投递闭包
        Task::async(function ($serv, $task_id, $data) {
            $i = 0;
            while ($i < 10) {
                $i++;
                echo $i;
                sleep(1);
            }
        });
        return "<a href=" . $url. ">授权</a>";
    }

    public function hello()
    {
        return 'hello';
    }
}
